class OrderItem:
    """订单中的商品项"""
    def __init__(self, name, quantity, unit_price):
        self.name = name  # 商品名称
        self.quantity = quantity  # 数量
        self.unit_price = unit_price  # 单价
        self.amount = quantity * unit_price  # 金额，自动计算

class Order:
    """订单类，包含订单的基本信息和商品列表"""
    def __init__(self, order_id, time):
        self.order_id = order_id  # 单号
        self.time = time  # 时间
        self.items = []  # 商品列表
        self.total_quantity = 0  # 总数量
        self.total_amount = 0.0  # 总额
        self.discounted_amount = 0.0  # 折后总额
        self.actual_paid = 0.0  # 实收金额
        self.change = 0.0  # 找零
        self.cashier = ""  # 收银员

    def add_item(self, item):
        """添加商品到订单"""
        self.items.append(item)
        # 更新总数量和总金额
        self.total_quantity += item.quantity
        self.total_amount += item.amount

    def set_payment_info(self, discounted_amount, actual_paid, change, cashier):
        """设置支付相关信息"""
        self.discounted_amount = discounted_amount
        self.actual_paid = actual_paid
        self.change = change
        self.cashier = cashier

    def display(self):
        """显示订单详情"""
        print(f"单号: {self.order_id}")
        print(f"时间: {self.time}")
        print("\n名称\t\t数量\t单价\t金额")
        print("-" * 40)
        for item in self.items:
            print(f"{item.name}\t{item.quantity}\t{item.unit_price:.2f}\t{item.amount:.2f}")
        print("-" * 40)
        print(f"总数: {self.total_quantity}\t\t总额: {self.total_amount:.2f}")
        print(f"折后总额: {self.discounted_amount:.2f}")
        print(f"实收: {self.actual_paid:.2f}\t找零: {self.change:.2f}")
        print(f"收银员: {self.cashier}")
        print("-" * 40)

# 创建订单实例
order = Order("DH202311010001", "2023-11-01 20:56:15")

# 添加商品
order.add_item(OrderItem("金士顿U盘8G", 1, 40.00))
order.add_item(OrderItem("创世16GTF卡", 1, 50.00))
order.add_item(OrderItem("读卡器", 1, 8.00))
order.add_item(OrderItem("网线2米", 1, 5.00))

# 设置支付信息
order.set_payment_info(103.00, 103.00, 0.00, "管理员")

# 显示订单
order.display()